package com.thwj.project.app.api;

import com.thwj.framework.web.domain.R;
import com.thwj.framework.web.service.TokenService;
import com.thwj.project.monitor.task.JobTask;
import com.thwj.project.push.enums.PushTemplateEnumNew;
import com.thwj.project.push.event.WxMpMessageEvent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Api(tags="app 测试相关接口 前端无需调用")
@RestController
@RequestMapping("/app/test")
public class AppTestController {


    @Autowired
    private TokenService tokenService;
    @Autowired
    ApplicationEventPublisher applicationEventPublisher;

    @Autowired
    JobTask jobTask;


    @ApiOperation(value = "测试公众号推送",notes = "获取当前用户的账户数据")
    @GetMapping("/testPush")
    public R<String> getUserAccount(@RequestParam Long userId) {

        List<WxMpTemplateData> templateDataList = new ArrayList<>();
        templateDataList.add(new WxMpTemplateData("first","恭喜你报名成功",""));
        templateDataList.add(new WxMpTemplateData("keyword1","10:00-22:00 周三 2022-06-07",""));
        templateDataList.add(new WxMpTemplateData("keyword2","杭州滨江区体育馆",""));
        templateDataList.add(new WxMpTemplateData("keyword3","张三",""));
        templateDataList.add(new WxMpTemplateData("keyword4","足球单挑训练赛",""));
        templateDataList.add(new WxMpTemplateData("remark","该活动取消政策 活动开始后2小时不可取消",""));

        applicationEventPublisher.publishEvent(
                WxMpMessageEvent.builder()
                        .userId(userId)
                        .miniAppPath("/pages/authentication/authentication")
                        .pushTemplateEnum(PushTemplateEnumNew.ACTIVITY_SIGN_UP_SUCCESS)
                        .templateDataList(templateDataList)
                        .build());
        return R.data("处理完成");
    }


    @ApiOperation(value = "测试公众号推送",notes = "获取当前用户的账户数据")
    @GetMapping("/testPush1")
    public R<String> pushAdminOrderPay() {
        jobTask.pushAdminOrderPay();
        return R.data("处理完成");
    }



}
